<%@ Page Language="C#" %>
<%@ Import namespace="IFXplus.Northwind"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    
    protected static string id = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        id = Request.QueryString["id"] + "";
        if (!IsPostBack)
        {
            Customer c = CustomerManager.GetCustomer(id);
            if (c == null)
            {
                lblMessage.Text = "Impossibile trovare customer con id = \"" + id + "\"";
                lblMessage.Visible = true;
                phDetails.Visible = false;
            }
            else
            {
                btnEdit.HRef = "customeredit.aspx?id=" + c.CustomerId;
                lblCustomerID.Text = c.CustomerId;
                lblCompanyName.Text = c.CompanyName;
                lblContactName.Text = c.ContactName;
                lblContactTitle.Text = c.ContactTitle;
                lblAddress.Text = c.Address;
                lblCity.Text = c.City;
                lblRegion.Text = c.Region;
                lblPostalCode.Text = c.PostalCode;
                lblCountry.Text = c.Country;
                lblPhone.Text = c.Phone;
                lblFax.Text = c.Fax;
            }
        }
    }
    
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        try
        {
            CustomerManager.DeleteCustomer(id);
            Response.Redirect("default.aspx");
        }
        catch (Exception ex)
        {
            lblMessage.Text = "ERRORE: " + ex.Message;
            lblMessage.Visible = true;
            phDetails.Visible = false;
        }

    }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Customer View</title>
</head>
<body>
	<form id="frmMain" runat="server">
    <div>
    	<asp:Label ID="lblMessage" runat="server" Text="" Visible="false"></asp:Label>
		<asp:PlaceHolder ID="phDetails" runat="server">
			CustomerID = <asp:Label ID="lblCustomerID" runat="server" Text=""></asp:Label><br />
			CompanyName = <asp:Label ID="lblCompanyName" runat="server" Text=""></asp:Label><br />
			ContactName = <asp:Label ID="lblContactName" runat="server" Text=""></asp:Label><br />
			ContactTitle = <asp:Label ID="lblContactTitle" runat="server" Text=""></asp:Label><br />
			Address = <asp:Label ID="lblAddress" runat="server" Text=""></asp:Label><br />
			City = <asp:Label ID="lblCity" runat="server" Text=""></asp:Label><br />
			Region = <asp:Label ID="lblRegion" runat="server" Text=""></asp:Label><br />
			PostalCode = <asp:Label ID="lblPostalCode" runat="server" Text=""></asp:Label><br />
			Country = <asp:Label ID="lblCountry" runat="server" Text=""></asp:Label><br />
			Phone = <asp:Label ID="lblPhone" runat="server" Text=""></asp:Label><br />
			Fax = <asp:Label ID="lblFax" runat="server" Text=""></asp:Label><br />
		</asp:PlaceHolder>
		<hr />
		<a href="default.aspx">Torna alla lista</a> | <asp:LinkButton ID="btnDelete" runat="server" Text="Elimina" OnClick="btnDelete_Click" /> | <a id="btnEdit" runat="server">Modifica</a>
    </div>
    </form>
</body>
</html>

